# -*- coding: utf-8 -*-


import wx
import os
import actionmenu as action

from gettext import gettext as _

class ToolBar:

    def __init__(self,app):
        self.app = app
        """
        wx.ToolBar.__init__(self, -1, style = wx.TB_HORIZONTAL
                                 | wx.NO_BORDER
                                 | wx.TB_FLAT
                                 | wx.TB_TEXT)
        """
        self.tb = app.myframe.CreateToolBar( 
                                wx.TB_HORIZONTAL
                                 |wx.TB_DOCKABLE
                                 | wx.NO_BORDER
                                 | wx.TB_FLAT
                                 | wx.TB_TEXT
                                 )
        
        tsize = (20,20)
        
        new_bmp =  wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
        open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
        copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
        paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
        
        plus_bmp = self.png2bitmap("plus.png")        
        module_bmp = self.png2bitmap("module.png")
        
        self.tb.AddSeparator()
        self.tb.AddSimpleTool(10, new_bmp, _("New"), u"新建")
        self.tb.AddSimpleTool(20, open_bmp, u"打开", u"打开")
        
        self.tb.AddSeparator()
        self.tb.AddSimpleTool(30, copy_bmp, "Copy", "Copy")
        self.tb.AddSimpleTool(40, paste_bmp, u"生成", u"生成")
        
        self.tb.AddSeparator()        
        self.tb.AddSimpleTool(50, plus_bmp, u"map生成", u"map生成")        
        self.tb.AddSimpleTool(60, module_bmp, u"map生成", u"map生成")                
        
        self.tb.AddSeparator()
        
        act = action.ActionMenu(app)

        app.Bind(wx.EVT_TOOL, act.OnConsole, id=10)        
        app.Bind(wx.EVT_TOOL, act.OnLog, id=20)
        app.Bind(wx.EVT_TOOL, act.OnDoit, id=30)        
        app.Bind(wx.EVT_TOOL, act.OnGen, id=40)        
        app.Bind(wx.EVT_TOOL, self.OnTest, id=50)
        self.tb.Realize()
                
        
        
        """
        cbID = wx.NewId()
        tb.AddControl(
            wx.ComboBox(
                tb, cbID, "", choices=["", "This", "is a", "wxComboBox"],
                size=(150,-1), style=wx.CB_DROPDOWN
                ))
        """
        
    def OnTest(self,event):
        self.ToggleTool(50,False)
        print "test"
        
    def OnView(self,event):
        
        mgr = self.app.getMgr()
        mgr.AddPane(self.app.p1, wx.LEFT, )
        mgr.Update()
        print "on view"
        #event.Skip()
        
    def getToolBar(self):
        return self.tb
     
    def png2bitmap(self, filename):
        filename = "images\\"+filename
        tsize=(16,16)
        if not os.path.exists(filename) and not os.path.isabs(filename):
            print os.getcwd()
            filename = os.path.normcase(os.path.join(os.getcwd(), filename))
        
        image = wx.Image(filename)
        if image.Ok():
            return image.ConvertToBitmap()
        else:
            return wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
        
